﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using ZK.Common.ProModels;
using static ZK.Common.ProModels.SysDefinitionEnum;

namespace ZK.Common
{
    public class WebApiService
    {
        /*控制器名称*/
        private static readonly string controlName = "autoControlTransport/";
        private static readonly string CNTransportProcess = "transportProcess/";
        private static readonly string CNSmallCar = "smallCar/";
        /*方法名称*/
        private static readonly string truckAdmissionUrl = controlName + "truckAdmission";//车辆入场
        private static readonly string truckExitUrl = controlName + "truckExit";//车辆出场
        private static readonly string getTruckYxInfoUrl = controlName + "getTruckYxInfo";//获取当前车辆信息
        private static readonly string truckLoadingUrl = controlName + "truckLoading";//车辆装车
        private static readonly string truckTareUrl = controlName + "truckTare";//车辆除皮
        private static readonly string truckUnloadingUrl = controlName + "truckUnloading";//车辆卸车
        private static readonly string truckWeighUrl = controlName + "truckWeigh";//车辆称重
        private static readonly string truckWeightBillUrl = controlName + "truckWeightBill";//生成磅单
        private static readonly string insertCoalWeighturl = controlName + "insertCoalWeight";//cs盘煤过磅计量添加
        private static readonly string selectTruckStateUrl = controlName + "selectTruckState";//cs端验证当前车辆是否为盘煤车辆
        private static readonly string getPrintWeightBillUrl = controlName + "getPrintWeightBill";//打印磅单状态更改
        private static readonly string printWeightBillUrl = controlName + "printWeightBill";//打印磅单状态更改
        private static readonly string releaseUrl = CNTransportProcess + "release";//手动放行（道闸）记录
        private static readonly string csSmallCarUrl = CNSmallCar + "csSmallCar";//little car serach 
        #region 登录
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="errorStr"></param>
        /// <returns></returns>
        public static ApiResponseDto Login(string userName, string password, out string errorStr)
        {
            ApiResponseDto dto = new ApiResponseDto();
            string ret = "";
            bool b = false;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("username", userName);
            data.Add("password", password);
            try
            {
                string url = InterfaceExecute.GetUrl("login/login", data);
                ret = HttpClientUtil.doPostMethodToObj(url, out b);
                //UserLoginDto userLoginDto = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginDto>(ret);
                JObject ja = InterfaceExecute.getJobj(out errorStr, b, ret);
                if (errorStr == "" && ja != null)
                {
                    JToken reData = (JToken)ja["data"];
                    if (reData != null && reData.Count() > 0)
                    {
                        AppSession.UserInfo.Token = reData["deptList"][0]["token"].ToString();
                        AppSession.UserInfo.Id = int.Parse(reData["id"].ToString());
                        AppSession.UserInfo.UserName = reData["userName"].ToString();
                        AppSession.UserInfo.TelePhone = reData["telephone"].ToString();
                        AppSession.UserInfo.DeptName = reData["deptName"].ToString();

                        AppConfigHelper.SetAppSettings("Token", AppSession.UserInfo.Token);//设置配置文件的token
                    }
                    dto.Msg = ja["msg"].ToString();
                    dto.Success = bool.Parse(ja["success"].ToString());
                }
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("用户名为：" + userName + ",登录接口异常返回数据为[" + ret + "],异常信息为:" + ex.Message);
                errorStr = "error";
            }

            return dto;
        }

        #endregion

        #region 小车道路接口
        /// <summary>
        /// 小车道路接口
        /// </summary>
        /// <param name="carNum"></param>
        /// <returns></returns>
        public static ResultDataBase<SmallCarDto> CsSmallCar(string carNum)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("carNo", carNum);
            string url = InterfaceExecute.GetUrl(csSmallCarUrl, data);
            try
            {
                ret = HttpClientUtil.doGetMethodToObj(url, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<SmallCarDto>>(ret);
        }
        #endregion

        #region cs盘煤过磅计量添加
        /// <summary>
        /// cs盘煤过磅计量添加
        /// </summary>
        /// <param name="sendTruckAdmissionDto"></param>
        /// <returns></returns>
        public static ResultDataBase<ResultPlanTruckCoalWeightDto> InsertCoalWeight(SendPlanCoalweightDto sendPlanCoalweightDto)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", sendPlanCoalweightDto.truckNo);
            data.Add("cardNo", sendPlanCoalweightDto.cardNo);
            data.Add("imgs1", sendPlanCoalweightDto.imgs1);
            data.Add("mz", sendPlanCoalweightDto.mz.ToString());
            string strData = HttpClientUtil.GetJsonStr(data);
            Common.Log4.LogManage.WriteInfo("InsertCoalWeight-接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(insertCoalWeighturl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<ResultPlanTruckCoalWeightDto>>(ret);
        }
        #endregion

        #region cs端验证当前车辆是否为盘煤车辆
        /// <summary>
        /// cs端验证当前车辆是否为盘煤车辆
        /// </summary>
        /// <param name="truckNo">车牌号</param>
        /// <param name="cardNo">卡号</param>
        /// <returns></returns>
        public static ResultDataBase<string> SelectTruckState(string truckNo, string cardNo)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", truckNo);
            data.Add("cardNo", cardNo);
            Common.Log4.LogManage.WriteInfo("SelectTruckState-接口传入参数分别为：" + truckNo + "," + cardNo + ",");
            string url = InterfaceExecute.GetUrl(selectTruckStateUrl, data);
            try
            {
                ret = HttpClientUtil.doGetMethodToObj(url, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        #endregion

        #region 打印磅单状态更改
        /// <summary>
        /// 打印磅单状态更改
        /// </summary>
        /// <param name="wbid">榜单id</param>
        /// <returns></returns>
        public static ResultDataBase<string> GetPrintWeightBill(string wbid)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("wbid", wbid);
            data.Add("billState", "1");
            Common.Log4.LogManage.WriteInfo("getPrintWeightBill-接口传入参数分别为：" + wbid + ",");
            string url = InterfaceExecute.GetUrl(getPrintWeightBillUrl, data);
            try
            {
                ret = HttpClientUtil.doGetMethodToObj(url, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        #endregion

        #region 打印磅单列表显示
        /// <summary>
        /// 打印磅单列表显示
        /// </summary>
        /// <param name="wbid">榜单id</param>
        /// <returns></returns>
        public static ResultDataBase<List<ResultWeightBillDto>> PrintWeightBill(SendPrintWeightBillDto sendPrintWeightBillDto)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            string strData = Newtonsoft.Json.JsonConvert.SerializeObject(sendPrintWeightBillDto);
            Common.Log4.LogManage.WriteInfo("getPrintWeightBill-接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(printWeightBillUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<List<ResultWeightBillDto>>>(ret);
        }
        #endregion

        #region 手动放行（道闸）记录
        /// <summary>
        /// 手动放行（道闸）记录
        /// </summary>
        /// <param name="flag">1轻磅 2重磅</param>
        /// <param name="imgs1">图片路径字符串多个逗号隔开。</param>
        /// <returns></returns>
        public static ReleaseModel<string> Release(int flag, string imgUrl)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("flag", flag.ToString());
            data.Add("imgUrl", imgUrl);
            Common.Log4.LogManage.WriteInfo("Release-接口传入参数分别为：" + flag + "," + imgUrl + ",");
            string url = InterfaceExecute.GetUrl(releaseUrl, data);
            try
            {
                ret = HttpClientUtil.doGetMethodToObj(url, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ReleaseModel<string>>(ret);
        }
        #endregion

        #region 通过卡号车牌号查询相关信息
        /// <summary>
        /// 通过卡号车牌号查询相关信息
        /// </summary>
        /// <param name="cardNum"></param>
        /// <param name="truckNum"></param>
        /// <param name="errorStr"></param>
        /// <returns></returns>
        public static TransBasicInfo GetInfoByCardTrunkNum(string cardNum, string truckNum, out string errorStr, int state = 0)
        {
            TransBasicInfo model = new TransBasicInfo();
            string ret = "";
            bool b = false;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("card_no", cardNum);
            data.Add("truck_no", truckNum);
            data.Add("state", state.ToString());
            Common.Log4.LogManage.WriteInfo("GetInfoByCardTrunkNum-接口传入参数分别为：" + cardNum + "," + truckNum + "," + state.ToString());
            string url = InterfaceExecute.GetUrl("autoTransport/getAllInfo", data);
            try
            {
                ret = HttpClientUtil.doGetMethodToObj(url, out b);
                Common.Log4.LogManage.WriteInfo("请求getAllInfo接口返回:" + ret);
                JObject ja = InterfaceExecute.getJobj(out errorStr, b, ret);
                if (errorStr == "" && ja != null)
                {
                    if (ja["codeStatus"].ToString() == "4010")
                    {
                        Login(MyCustomConfig.userInfo.UserName, MyCustomConfig.userInfo.UserPwd, out errorStr);
                        return GetInfoByCardTrunkNum(cardNum, truckNum, out errorStr);
                    }
                    model.IsSuccess = bool.Parse(ja["success"].ToString());
                    model.MsgData = ja["msg"].ToString();

                    JToken cardInfo = ja["data"];
                    if (cardInfo == null || cardInfo.Count() == 0)
                    {
                        return model;
                    }
                    //model.BName = cardInfo["bname"].ToString();
                    if (cardInfo["carrier_name"] != null)
                        model.CarrierName = cardInfo["carrier_name"].ToString();
                    if (cardInfo["coal_name"] != null)
                        model.CoalName = cardInfo["coal_name"].ToString();
                    if (cardInfo["contract_name"] != null)
                        model.ContractName = cardInfo["contract_name"].ToString();
                    if (cardInfo["contract_type"] != null && !string.IsNullOrEmpty(cardInfo["contract_type"].ToString()))
                        model.ContractType = int.Parse(cardInfo["contract_type"].ToString());
                    if (cardInfo["cname"] != null)
                        model.CustomerName = cardInfo["cname"].ToString();
                    //model.Price = double.Parse(cardInfo["price"].ToString());
                    if (cardInfo["truck_type_name"] != null)
                        model.TruckTypeName = cardInfo["truck_type_name"].ToString();
                    if (cardInfo["truck_no"] != null)
                        model.truckNum = cardInfo["truck_no"].ToString();
                    if (cardInfo["rated_load"] != null && !string.IsNullOrEmpty(cardInfo["rated_load"].ToString()))
                        model.ratedLoad = decimal.Parse(cardInfo["rated_load"].ToString());
                    if (cardInfo["tare"] != null && !string.IsNullOrEmpty(cardInfo["tare"].ToString()))
                        model.tare = decimal.Parse(cardInfo["tare"].ToString());
                    if (cardInfo["weightFloatingMz"] != null && !string.IsNullOrEmpty(cardInfo["weightFloatingMz"].ToString()))
                        model.weightFloatingMz = decimal.Parse(cardInfo["weightFloatingMz"].ToString());
                    if (cardInfo["weightFloatingPz"] != null && !string.IsNullOrEmpty(cardInfo["weightFloatingPz"].ToString()))
                        model.weightFloatingPz = decimal.Parse(cardInfo["weightFloatingPz"].ToString());
                    if (cardInfo["yx_state"] != null && !string.IsNullOrEmpty(cardInfo["yx_state"].ToString()))
                    {
                        model.yx_State = (SysDefinitionEnum.YxState)int.Parse(cardInfo["yx_state"].ToString());
                    }
                    if (ja["codeStatus"] != null && !string.IsNullOrEmpty(ja["codeStatus"].ToString()))
                    {
                        model.codeStatus = int.Parse(ja["codeStatus"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return model;
        }
        #endregion

        #region 获取当前车辆信息接口
        /// <summary>
        /// 获取当前车辆信息接口
        /// </summary>
        /// <param name="truckNo"></param>
        /// <param name="cardNo"></param>
        /// <returns></returns>
        public static ResultDataBase<TruckYxInfo> GetTruckYxInfo(string truckNo, string cardNo = "")
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", truckNo);
            data.Add("cardNo", cardNo);
            Common.Log4.LogManage.WriteInfo("GetTruckYxInfo-接口传入参数分别为：" + truckNo + "," + cardNo + ",");
            string url = InterfaceExecute.GetUrl(getTruckYxInfoUrl, data);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, null, out b);

            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<TruckYxInfo>>(ret);
        }

        #endregion

        #region 车辆入场接口
        /// <summary>
        /// 车辆入场接口
        /// </summary>
        /// <param name="cardNo">卡号 </param>
        /// <param name="imgs1">抓拍图片1,多张图片用逗号隔开 ,</param>
        /// <param name="truckNo">车牌号</param>
        /// <returns></returns>
        public static ResultDataBase<string> TruckAdmission(string cardNo, string imgs1, string truckNo)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", truckNo);
            data.Add("cardNo", cardNo);
            data.Add("imgs1", imgs1);
            string strData = HttpClientUtil.GetJsonStr(data);
            Common.Log4.LogManage.WriteInfo("TruckAdmission-接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(truckAdmissionUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        /// <summary>
        /// 车辆入场接口
        /// </summary>
        /// <param name="sendTruckAdmissionDto"></param>
        /// <returns></returns>
        public static ResultDataBase<string> TruckAdmission(SendTruckAdmissionDto sendTruckAdmissionDto)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", sendTruckAdmissionDto.truckNo);
            data.Add("cardNo", sendTruckAdmissionDto.cardNo);
            data.Add("imgs1", sendTruckAdmissionDto.imgs1);
            data.Add("bfId", sendTruckAdmissionDto.bfId.ToString());
            Common.Log4.LogManage.WriteInfo("TruckAdmission接口传入参数分别为：" + sendTruckAdmissionDto.truckNo + "," + sendTruckAdmissionDto.cardNo + ",");
            string url = InterfaceExecute.GetUrl(truckAdmissionUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, HttpClientUtil.GetJsonStr(data), out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        #endregion

        #region 车辆出场接口
        /// <summary>
        /// 车辆出场接口
        /// </summary>
        /// <param name="cardNo">卡号 </param>
        /// <param name="imgs1">抓拍图片1,多张图片用逗号隔开 ,</param>
        /// <param name="truckNo">车牌号</param>
        /// <returns></returns>
        public static ResultDataBase<string> TruckExit(string cardNo, string imgs1, string truckNo)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", truckNo);
            data.Add("cardNo", cardNo);
            data.Add("imgs1", imgs1);
            string strData = HttpClientUtil.GetJsonStr(data);
            Common.Log4.LogManage.WriteInfo("TruckExit-接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(truckExitUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        #endregion

        #region 车辆装车接口
        /// <summary>
        /// 车辆装车接口
        /// </summary>
        /// <param name="cardNo">卡号 ,</param>
        /// <param name="imgs1">抓拍1,多张图片用逗号隔开 ,</param>
        /// <param name="truckNo">车牌号</param>
        /// <param name="bunkerId">仓场id ,</param>
        /// <param name="memo">备注 </param>
        /// <returns></returns>
        public static ResultDataBase<string> TruckLoading(string cardNo, string imgs1, string truckNo, int bunkerId, string memo)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", truckNo);
            data.Add("cardNo", cardNo);
            data.Add("imgs1", imgs1);
            data.Add("bunkerId", bunkerId.ToString());
            data.Add("memo", memo);
            string strData = HttpClientUtil.GetJsonStr(data);
            Common.Log4.LogManage.WriteInfo("TruckLoading-接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(truckLoadingUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        #endregion

        #region 车辆除皮接口
        /// <summary>
        /// 车辆除皮接口
        /// </summary>
        /// <param name="cardNo">卡号 </param>
        /// <param name="imgs1">抓拍图片1,多张图片用逗号隔开 ,</param>
        /// <param name="truckNo">车牌号</param>
        /// <param name="pz">皮重 ,</param>
        /// <param name="wgbid">地磅id</param>
        /// <returns></returns>
        public static ResultDataBase<string> TruckTare(string cardNo, string imgs1, string truckNo, decimal pz, int wgbid)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", truckNo);
            data.Add("cardNo", cardNo);
            data.Add("imgs1", imgs1);
            data.Add("pz", pz.ToString());
            data.Add("wgbid", wgbid.ToString());
            string strData = HttpClientUtil.GetJsonStr(data);
            Common.Log4.LogManage.WriteInfo("CarOut接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(truckTareUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        /// <summary>
        /// 车辆除皮接口
        /// </summary>
        /// <param name="sendTruckTareDto"></param>
        /// <returns></returns>
        public static ResultDataBase<string> TruckTare(SendTruckTareDto sendTruckTareDto)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", sendTruckTareDto.truckNo);
            data.Add("cardNo", sendTruckTareDto.cardNo);
            data.Add("imgs1", sendTruckTareDto.imgs1);
            data.Add("pz", sendTruckTareDto.pz.ToString());
            data.Add("wgbid", sendTruckTareDto.wgbid.ToString());
            data.Add("coalmineOutput", sendTruckTareDto.coalmineOutput.ToString());
            data.Add("mz", sendTruckTareDto.mz.ToString());
            string strData = HttpClientUtil.GetJsonStr(data);
            Common.Log4.LogManage.WriteInfo("CarOut接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(truckTareUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        #endregion

        #region 车辆卸车接口
        /// <summary>
        /// 车辆卸车接口
        /// </summary>
        /// <param name="cardNo">卡号 </param>
        /// <param name="imgs1">抓拍图片1,多张图片用逗号隔开 ,</param>
        /// <param name="truckNo">车牌号</param>
        /// <param name="buckleWeight">扣重</param>
        /// <param name="buckleWeightReason">扣重原因</param>
        /// <param name="bunkerId">仓场id ,</param>
        /// <param name="memo">备注 </param>
        /// <returns></returns>
        public static ResultDataBase<string> TruckUnloading(SendTruckUnloadingDto sendTruckUnloadingDto)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            string strData = Newtonsoft.Json.JsonConvert.SerializeObject(sendTruckUnloadingDto);
            Common.Log4.LogManage.WriteInfo("TruckUnloading接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(truckUnloadingUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        #endregion

        #region 车辆称重接口
        /// <summary>
        /// 车辆称重接口
        /// </summary>
        /// <param name="cardNo">卡号 </param>
        /// <param name="imgs1">抓拍图片1,多张图片用逗号隔开 ,</param>
        /// <param name="truckNo">车牌号</param>
        /// <param name="mz">毛重</param>
        /// <param name="wgbid">地磅id</param>
        /// <returns></returns>
        public static ResultDataBase<string> TruckWeigh(string cardNo, string imgs1, string truckNo, double mz, int wgbid)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", truckNo);
            data.Add("cardNo", cardNo);
            data.Add("imgs1", imgs1);
            data.Add("mz", mz.ToString());
            data.Add("wgbid", wgbid.ToString());
            string strData = HttpClientUtil.GetJsonStr(data);
            Common.Log4.LogManage.WriteInfo("TruckWeigh接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(truckWeighUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<string>>(ret);
        }
        #endregion

        #region 生成磅单接口
        /// <summary>
        /// 生成磅单接口
        /// </summary>
        /// <param name="cardNo">卡号 </param>
        /// <param name="truckNo">车牌号</param>
        /// <returns></returns>
        public static ResultDataBase<ResultWeightBillDto> TruckWeightBill(string cardNo, string truckNo)
        {
            string ret = "";
            bool b = false;
            string errorStr = string.Empty;
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("truckNo", truckNo);
            data.Add("cardNo", cardNo);
            string strData = HttpClientUtil.GetJsonStr(data);
            Common.Log4.LogManage.WriteInfo("TruckWeightBill接口传入参数分别为：" + strData + ",");
            string url = InterfaceExecute.GetUrl(truckWeightBillUrl);
            try
            {
                ret = HttpClientUtil.doPostMethodToObj(url, strData, out b);
            }
            catch (Exception ex)
            {
                errorStr = ex.ToString();
                Common.Log4.LogManage.WriteErr(errorStr);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultDataBase<ResultWeightBillDto>>(ret);
        }
        #endregion

        #region 上传抓的图片
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="errorStr"></param>
        /// <returns></returns>
        public static string HttpUploadFile(string filePath, out string errorStr)
        {
            string ret = "";
            errorStr = "";
            bool b = false;
            Encoding encoding = Encoding.UTF8;
            string boundary = DateTime.Now.Ticks.ToString("x");
            byte[] boundarybytes = Encoding.ASCII.GetBytes("\r\n----" + boundary + "\r\n");
            byte[] endbytes = Encoding.ASCII.GetBytes("\r\n----" + boundary + "--\r\n");

            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("systemType", "RoadGateRecord"); //传文件存储路径
            data.Add("filePath", "RoadGateRecord/" + DateTime.Now.ToString("yyyyMMdd"));
            string url = InterfaceExecute.GetMediaUrl("importFile", data);

            try
            {
                //1.HttpWebRequest
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.ContentType = "multipart/form-data; boundary=--" + boundary;
                request.Method = "POST";
                request.KeepAlive = true;
                request.Credentials = CredentialCache.DefaultCredentials;
                //request.Timeout = 10000;

                using (Stream stream = request.GetRequestStream())
                {
                    string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type:application/octet-stream\r\n\r\n";
                    byte[] buffer = new byte[4096];
                    int bytesRead = 0;
                    stream.Write(boundarybytes, 0, boundarybytes.Length);
                    string header = string.Format(headerTemplate, "file", Path.GetFileName(filePath));
                    byte[] headerbytes = encoding.GetBytes(header);
                    stream.Write(headerbytes, 0, headerbytes.Length);
                    using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                    {
                        while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            stream.Write(buffer, 0, bytesRead);
                        }
                    }
                    stream.Write(endbytes, 0, endbytes.Length);
                }
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                ret = HttpClientUtil.getResponseString(response);
                JObject ja = InterfaceExecute.getJobj(out errorStr, b, ret);
                if (errorStr == "" && ja != null)
                {
                    return ja["data"].ToString();
                }
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("上传抓拍图片返回数据为[" + ret + "],异常信息为:" + ex.Message);
                errorStr = ex.Message;
            }
            return "";
        }

        #endregion


    }
}
